home *** CD-ROM | disk | FTP | other *** search
- Path: warrane.connect.com.au!ieaust1!Damien_Gardner
- From: Damien_Gardner@ieaust.org.au (Damien Gardner)
- Reply-To: Damien_Gardner@ieaust.org.au
- Newsgroups: comp.lang.c
- Distribution: world
- Subject: Interrupt-driven Serial I/O
- Date: 08 Feb 1996 04:31:40 GMT
- Message-ID: <2575630302.506400733@ieaust.org.au>
- Organization: Institution of Engineers, Australia
-
- Hi there! I'm in the midst of trying to write a Serial I/O library
- (Interrupt driven). The Transmit routine (which is hooked into int 0x1c,
- the 55ms timer tick interrupt), works fine. However, I cannot get the
- receive routine (which is hooked into the appropriate Int for the Com port)
- to work (it seems that it is not even being called!).
- I've got it incrementing a global variable (inttemp), each time it is
- called, and it is not incrementing. Could someone who has managed to
- get this sort of thing to work, give me a few tips?
- (Sorry about the messy code, but I've spent the entire day,
- adding, deleting, and changing bits.
-
- Begin file fragment
- >>>>>>
- void setintr(void)
- {
-
- //print Status information here (removed)
-
- /* save the old interrupt vector */
- oldhandler = getvect(INTR);
- oldhandler2 = getvect(0x1C);
-
- /* install the new interrupt handler */
- setvect(INTR, rcv_handler); // install the receive handler.
- setvect(0x1C, trx_handler); // install the transmit handler.
- // enable IRQ (INTR - 0x08)
- outportb(0x21, inportb(0x21) & (0xFF - (1 << (INTR - 0x08))));
- outportb(PortAddr + 4, 11); // Enable RTS, DTR, and OUT2
- outportb(PortAddr + 1, 1); // enable the RC Interrupt
- }
-
- void remintr(void)
- {
- outportb(0x21, inportb(0x21) | (1 << (INTR - 0x08)));
- outportb(PortAddr + 1, 0); // disable all Interrupts from the Com port.
- /* reset the old interrupt handler */
- setvect(INTR, oldhandler);
- setvect(0x1C, oldhandler2);
- }
- void interrupt rcv_handler(void)
- {
- char tmp;
- inttemp++;
- disable();
- while (!((tmp = inp(PortAddr + 2)) & 1) && (tmp & 4))
- {
- tmp = inportb(PortAddr);
- if (!RC_full()) RC_put(tmp);
- }
- enable();
- }
- <<<<<<<
- End file fragment
-
- Notes:
-
- char INTR is an 8-bit value, defined globally, and set by another routine -
-
- it contains the Int number to install the rcv_handler on.
- (= com IRQ + 0x08)
-
- unsigned int PortAddr is a 16-bit value, defined globally, and set by
- another routine - it contains the base Address of the required
- serial port.
-
- I set OUT2 (in the Modem Control Register) high, as I beleive that this is
- required, to enable interrupts out of the 8250/16550. - I got this from a
- Pascal modem library, called 'comm_tp5'. If anyone knows where I can get
- the 'c' version of this, I *really* appreciate it! - That'll mean that
- I won't have to continue with this bloody thing!
-
- Cheers,
-
- Damien Gardner Jnr
- Moderator, Frequent Questions,
- Engineering OnLine, Australia.
- February 7, 1996
-